/***************************************************************************
 *   Copyright (C) 2008 by Philipp Müller                                  *
 *   philipp.mueller@gmx.de                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
 ***************************************************************************/

#include <qapplication.h>

#include "qtvomp.h"

int main( int argc, char ** argv )
{
    QApplication App( argc, argv );
    App.setApplicationName( "QtVomp" ); //needed for Phonon/DBUS

    QHostAddress server;

    //Parse the command line arguments
    QStringList arguments = App.arguments();

    for ( int i = 1; i < arguments.size(); ++i )
    {
        qDebug() << "main: argument passed to app:" << arguments.at( i );
        //Help output

        if ( arguments.at( i ) == "-h" )
        {
            printf( "QtVomp has following options:\n" );
            printf( "-h: this text\n" );
            printf( "-s: bind QtVomp to this IP address of the server. Searching for servers is then disabled\n" );
            return false;
        }

        //IP address of server given
        if ( arguments.at( i ) == "-s" )
        {
            if ( arguments.size() > i )
            {
                server = QHostAddress( arguments.at( i + 1 ) );

                if ( server.isNull() )
                {
                    printf( "IP address options set, but no valid IP address provided\n" );
                    return true;
                }

                qDebug() << "main: server IP address set to: " << arguments.at( i + 1 );
            }
            else
            {
                printf( "IP address options set, but no IP address provided\n" );
                return true;
            }

            i++;
        }
    }

    MainWindow * mw = new MainWindow( server );

    mw->show();

    App.connect( &App, SIGNAL( lastWindowClosed() ), &App, SLOT( quit() ) );
    return App.exec();
}
